#
# @lc app=leetcode.cn id=367 lang=python3
#
# [367] 有效的完全平方数
#

# @lc code=start
class Solution:
    def searchSqrt(self, num: int, left: int, right: int) -> bool:
        mid = int((left + right) / 2)
        if left == right or right - left == 1:
            return mid * mid == num
        if mid * mid < num:
            return self.searchSqrt(num, mid, right)
        elif mid * mid > num:
            return self.searchSqrt(num, left, mid)
        else:
            return True

    def isPerfectSquare(self, num: int) -> bool:
        return self.searchSqrt(num, 1, num)

# @lc code=end

